package com.example.duomeitijuhe.db;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import com.example.duomeitijuhe.bean.GetInternetDataBean;
import com.example.duomeitijuhe.constant.FinalConstant;

import java.util.ArrayList;

/**
 * Created by Michael on 2014/10/13.
 */
public class OperateDatabase {

    //表名

    private Context context;

    private int version;

    private UserDatabaseHelper userDatabaseHelper;

    private SQLiteDatabase database;

    public OperateDatabase(Context context,int version){

        this.context = context;
        this.version = version;
        userDatabaseHelper = new UserDatabaseHelper(context, FinalConstant.DB_NAME,null,version);
        database = userDatabaseHelper.getWritableDatabase();
    }

    public Cursor queryDb(String tableName){
        Cursor cursor = database.query(tableName,null,null,null,null,null,null);
        return cursor;


    }

    public void insertDbAccount(String account,String password){
        ContentValues values = new ContentValues();
        values.put("account",account);
        values.put("password",password);
        database.insert("Account",null,values);
        values.clear();
    }

    public void insertDbToken(String platform,String userId,String token){
        ContentValues values = new ContentValues();
        values.put("platform",platform);
        values.put("userid",userId);
        values.put("token",token);
        //values.put("date","2014-10-14");
        database.insert("Token",null,values);
        values.clear();

    }

    public void insertDbInternetData(GetInternetDataBean getInternetDataBean){
        ContentValues values = new ContentValues();
        values.put("userId",getInternetDataBean.getUserId());
        values.put("weiboId",getInternetDataBean.getWeiboId());
        values.put("senderId",getInternetDataBean.getSenderId());
        values.put("senderName",getInternetDataBean.getSenderName());
        values.put("senderIconUrl",getInternetDataBean.getSenderIconUrl());
        values.put("sendTime",getInternetDataBean.getSendTime());
        values.put("content",getInternetDataBean.getContent());
        values.put("contentPictureUrl",getInternetDataBean.getContentPictureUrl());
        values.put("isRetransmit",getInternetDataBean.getIsRetransmit());
        values.put("originalSenderId",getInternetDataBean.getOriginalSenderId());
        values.put("originalSenderName",getInternetDataBean.getOriginalSenderName());
        values.put("originalSenderIconUrl",getInternetDataBean.getOriginalSenderIconUrl());
        values.put("originalContent",getInternetDataBean.getOriginalContent());
        values.put("originalPictureUrl",getInternetDataBean.getOriginalPictureUrl());


        database.insert("InternetData",null,values);
        values.clear();
    }

    public void closeDb(){
        database.close();
    }
}
